#!/bin/bash
# shellcheck source=/dev/null
source ./common.sh

LANG_LINE="LANG=en_US.UTF-8"
LC_ALL_LINE="LC_ALL=en_US.UTF-8"
LANGUAGE_LINE="LANGUAGE=en_US.UTF-8"
LOCALE_FILE="/etc/default/locale"

function installCnFont() {
    check_command fc-list fontconfig
    echo "=====install cn font ======="
    if [ -f "$LOCALE_FILE" ]; then
        if ! grep -q "^${LANG_LINE}" "$LOCALE_FILE"; then
            echo "$LANG_LINE" >> "$LOCALE_FILE"
        fi
        if ! grep -q "^${LC_ALL_LINE}" "$LOCALE_FILE"; then
            echo "$LC_ALL_LINE" >> "$LOCALE_FILE"
        fi
        if ! grep -q "^${LANGUAGE_LINE}" "$LOCALE_FILE"; then
            echo "$LANGUAGE_LINE" >> "$LOCALE_FILE"
        fi
        source "$LOCALE_FILE"
    else
        echo "Locale file $LOCALE_FILE does not exist."
    fi
    echo ">>>>>>>>当前语言环境："
    locale
    #update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
}

function installCnFont-ubuntu() {
    installCnFont
    install_cmd fonts-wqy-zenhei
    fc-cache -fv
    echo ">>>>>>>>当前中文包："
    fc-list :lang=zh
    
    back_exit
}

function installCnFont-centos() {
    installCnFont
    install_cmd wqy-microhei-fonts
    fc-cache -fv
    echo ">>>>>>>>当前中文包："
    fc-list :lang=zh
    
    back_exit
}


execute_base_os installCnFont